Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(biome_glob): add dedicated crate for globs #4609

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Conaclos
Copy link
Member

@Conaclos Conaclos commented Nov 20, 2024

Summary

Move RetsrictedGlob from biome_js_analyze to a dedicated crate.
This allows us to use RetsrictedGlob outside biome_js_analyze.

Also, I renamed RetsrictedGlob into Glob. Possible alternative names are GlobPattern and Pattern.

I added some documentation for the crate and put optional dependencies behind feature flags.

Test Plan

CI must pass.

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Nov 20, 2024
@Conaclos Conaclos requested review from a team November 20, 2024 21:18
Copy link

codspeed-hq bot commented Nov 20, 2024

CodSpeed Performance Report

Merging #4609 will not alter performance

Comparing conaclos/biome_glob (03e4540) with main (03cd04a)

Summary

✅ 97 untouched benchmarks

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @Conaclos! Looking forward to use this crate in other places :)

I left some feedback around docs. Overall, we follow this pattern:

  1. Explain feature
  2. Explain example
  3. Show code example

@@ -1,31 +1,86 @@
use biome_rowan::{TextRange, TextSize};
//! biome_glob provides a glob and glob list with exceptions matching.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! biome_glob provides a glob and glob list with exceptions matching.
//! `biome_glob` provides a glob and glob list with exceptions matching.

crates/biome_glob/src/lib.rs Outdated Show resolved Hide resolved
crates/biome_glob/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines +12 to +14
//! let glob = "*.rs".parse::<Glob>().expect("correct glob");
//! assert!(glob.is_match("lib.rs"));
//! assert!(!glob.is_match("src/lib.rs"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't show the usage of FromStr::from_str and we should add it.

Also, I would remove the is_match because the previous paragraph didn't mention the is_match function. If you intend the keep is_match in the example, you should explain it in the previous paragraph, and explain why src/lib.rs isn't a match, and why lib.rs is a match.

//! When a path is expected to be matched against several globs,
//! you should compile the path into a [CandidatePath].
//! [CandidatePath] may speed up matching against several globs.
//!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a paragraph that explains the example.

//!
//! ## Matching against multiple globs and exceptions
//!
//! biome_glob supports negated globs, which are particularly useful for encoding exceptions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! biome_glob supports negated globs, which are particularly useful for encoding exceptions.
//! biome_glob supports exceptions - or negated globs -, which are particularly useful for encoding exceptions.

What "encoding expectations" actually mean? We could try to use simpler language.

I would add a small link/reference to git negated globs. What do you think?

crates/biome_glob/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 39 to 40
//! In the following example we accept all files in the `src` dierctory, except the ones ending with the `txt` extension.
//!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that we explain the example, but the example is incorrect 😅 there's no src directory. Also, you should explain what matches_with_exceptions does and how it behaves compared with is_match

Comment on lines +58 to +63
//! - star `*` that matches zero or more characters inside a path segment
//! - globstar `**` that matches zero or more path segments
//! - Use `\*` to escape `*`
//! - `?`, `[`, `]`, `{`, and `}` must be escaped using `\`.
//! These characters are reserved for future use.
//! - Use `!` as first character to negate the glob
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should provide a minimal example for each bullet that we explain

//! - Use `!` as first character to negate the glob
//!
//! A path segment is delimited by path separator `/` or the start/end of the path.
//!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should have a brief explanation of the features available by this crate

Conaclos and others added 2 commits November 21, 2024 14:12
@cr7pt0gr4ph7
Copy link
Contributor

Just a small nit-pick: RetsrictedGlob should be RestrictedGlob :)

On a (only partially) related note:

  • What's the relationship between biome_service::matcher::Pattern and RestrictedGlob?
  • Is there are reason that prevents us from unifying the two?

@ematipico
Copy link
Member

The idea is to get rid of Pattern. See #4611 for the whole plan, help is very welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants